<extend name="Index:base" />
<block name="content">
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <!-- 面包屑导航 -->
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{:U('Admin/Index/index')}">首页</a>
                </li>
                <li class="active">{$title}</li>
            </ul>
        </div>

        <div class="page-content">

            <!-- 页面导航 -->
            <div class="page-header">
                <h1>
                    {$title}
                    <small>
                        <i class="icon-double-angle-right"></i>
                         查看
                    </small>
                </h1>
            </div>

            <!-- 添加按钮 -->
            <div class="row" style="padding:0px;height:auto;overflow:hidden;margin-bottom:10px;">
                <div class="col-xs-12 col-sm-8">
                    <a class="btn btn-primary pull-left" style="padding:1px 10px;" href="{:U('Admin/Accesslist/addAccess')}">
                        <i class="icon-plus-sign bigger-125"></i>
                        添加权限
                    </a>
                </div>
                <div class="col-xs-12 col-sm-4">
                    <form action="" method="get">
                        <div class="input-group pull-right">
                            <input class="form-control search-query" type="text" value="{$Think.get.searchval}" name="searchval" placeholder="输入搜索内容...">
                            <span class="input-group-btn">
                                <button class="btn btn-info btn-sm" type="submit">
                                    Search
                                    <i class="icon-search icon-on-right bigger-110"></i>
                                </button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div class="table-responsive">
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th class="width-15">规则名称</th>
                                    <th class="width-25">规则标识</th>
                                    <th class="width-15">附加条件</th>
                                    <th class="width-15">所属模块</th>
                                    <th>状态</th>
                                    <th style="width:80px">操作</th>
                                </tr>
                            </thead>
                            <!--一行的开始-->
                            <!--遍历查询到的数据-->
                            <tbody>
                                <volist name="data" id="vo">
                                <tr>
                                    <td>
                                        {$vo['id']}
                                    </td>
                                    <td>{$vo['title']}</td>
                                    <td>{$vo['name']}</td>
                                    <td>{$vo['term']}</td>
                                    <td>{$vo['moduleName']}</td>
                                    <td>
                                        <div class="col-xs-3">
                                            <label>
                                                <input id="access-tap" class="ace ace-switch ace-switch-6" type="checkbox" {$vo['status']?'checked':''} name="switch-{$vo['id']}">
                                                <span class="lbl"></span>
                                            </label>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                            <a name="table-edit" class="green" href="{:U('Admin/Accesslist/modifyAccess',array('id'=>$vo['id']))}">
                                                <i class="icon-pencil bigger-130"></i>
                                            </a>
                                            <a name="del_{$vo['id']}" class="red" data-toggle="modal" href="#deleteModal">
                                                <i class="icon-trash bigger-130"></i>
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                <!--遍历结束-->
                                </volist>

                                <tr style="padding:0px;">
                                    <td colspan=10>{$page}</td>
                                </tr>
                                <!--一行的结束--> 
                            </tbody>
                        </table>
                    </div>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->
    <!-- 中间部分结束 -->
    
    <!-- 删除按钮弹出层 -->
    <div class="modal modal-small fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width:300px;">
            <div class="modal-content" style="top:160px;left:80%;">
                <div class="modal-header" style="height:40px;padding:5px 10px;line-height:30px;">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <p class="bigger-120" id="myModalLabel">删除数据</p>
                </div>
                <div class="modal-body" style="height:70px;padding:5px 10px;line-height:60px;">
                    <p class="text-danger bigger-150">确定删除数据！</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-sm btn-danger" id="delete-data">删除</button>
                    <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <div id="success-info" class="alert alert-success fade in col-xs-4 hide" style="position:fixed;top:20px;left:35%;z-index:1000;">
        <button class="close" aria-hidden="true" data-dismiss="alert" type="button">×</button>
        <strong></strong>
    </div>
    <div id="error-info" class="alert alert-danger fade in col-xs-4 hide" style="position:fixed;top:20px;left:35%;z-index:1000;">
        <button class="close" aria-hidden="true" data-dismiss="alert" type="button">×</button>
        <strong></strong>
    </div>
    <!-- 删除按钮弹出层结束 -->
</block>
<block name="privatejs">
    <script type="text/javascript">
        jQuery(function($) {
            //设置当前页面的菜单高亮显示 开始
            var nownav = "#sidebar a[href*=Accesslist]";
            var parentattr = $(nownav).parent().parent().attr("class");
            $(nownav).parent().addClass('active');
            if (parentattr == 'submenu') {
                $(nownav).parent().parent().parent().addClass('active open');
            };
            //设置当前页面的菜单高亮显示 结束

            //全选js
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function(){
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
                    
            });
            
            //删除弹窗和信息提示
            $('#success-info').fadeOut(0);
            $('#error-info').fadeOut(0);
            
            var delid;
            var delline;
            $('a[name^=del]').on('click',function(){
                delid = ($(this).attr('name').split('_'))[1];
                delline = $(this).parent().parent().parent();
            });
           
            $('#delete-data').on('click',function(){
                $.ajax({
                       url:"__APP__/Admin/Accesslist/deleteAccess",
                       type:"post",
                       data:{id:delid},
                       success:function(data){
                            if (data == 1) {
                                warningInfo("#success-info","删除成功！");
                                location.href='';
                            }else if(data == 2){
                                warningInfo("#success-info","没有删除权限！");
                            }else{
                                warningInfo("#error-info","删除失败！");
                            }
                            $('#deleteModal').modal('hide');
                       }
                });
            });

            $('label').on('click','#access-tap',function(){
                var cgid = $(this).prop('name').split('-')[1];
                $.ajax({
                    url:"__APP__/admin/Accesslist/accessState",
                    type:'post',
                    data:{id:cgid},
                    success:function(data){
                        if (data == 1) {
                            warningInfo("#success-info","状态更新成功！");
                        }else if(data == 2){
                            warningInfo("#error-info","没有更新权限！");
                        }else{
                            warningInfo("#error-info","状态更新失败！");
                        }
                    }
                });
            });
                       
            //信息提示函数
            function warningInfo(id,info){
                $(id).removeClass('hide');
                $(id).fadeOut(0);
                $(id).children().eq(1).html(info);
                $(id).fadeToggle(0).delay(1000).fadeToggle(1000);
            }
        });
    </script>
</block>